import yagmail #支持python脚本发送邮件
import zipfile
import os

"""zqhjtqaaqtyobfad""" #授权码
#pip install yagmail -i https://pypi.tuna.tsinghua.edu.cn/simple

def send_Email(user='1037311544@qq.com',password='zqhjtqaaqtyobfad',host='smtp.qq.com',revice='1037311544@qq.com',report=None):
    """
    SMTP:邮件传输协议
    user:表示QQ邮箱的登录帐号--QQ邮箱号
    password:是通过设置生成授权码
    host:是指QQ邮箱服务器地址--smtp.qq.com

    :return:
    """
    #先进行登录--生成一个邮件连接对象
    yag = yagmail.SMTP(user=user,password=password,host=host)

    #定义一个邮件发送正文--要定义成列表形式
    contens = ["接口自动化邮件"]
    subject = 'hollow'

    #yag对象调用send方法开始发送邮件
    # yag.send(to=revice,subject=subject,contents=contens)

    #发送一个带附件的邮件
    #revice是指接收者
    #如果要定义多个接收者 revice=['xx.126.com','xx.163.com','xx.qq.com','xxx.126.com']
    yag.send(to=revice, subject=subject, contents=contens,attachments=report)
#定义一个函数用来发送邮件
def zipDir(outFile,senddir):
    zip = zipfile.ZipFile(outFile,'w',zipfile.ZIP_DEFLATED)
    for path, dirnames, filenames in os.walk(senddir):
        # print(path, dirnames, filenames)
        fpath = path.replace(senddir,'')
        for filename in filenames:
            zip.write(os.path.join(path,filename),os.path.join(fpath,filename))
    zip.close()


if __name__ == '__main__':
    # send_Email()

    # for root,dirname,filename in os.walk('../send-dir'):
    #     print(root,dirname,filename)
    zipDir('send-dir.zip','../send-dir')